// gets 'theArgName' param from the URL 'theUrl'
// http://www.evolt.org/article/Javascript_to_Parse_URLs_in_the_Browser/17/14435/?format=print
function argItems(theUrl, theArgName) {
	aUrl = theUrl.split('?');
	if (aUrl.length > 1) {
		sArgs = aUrl[1].split('&');
		r = '';
		for (var i = 0; i < sArgs.length; i++) {
			if (sArgs[i].slice(0,sArgs[i].indexOf('=')) == theArgName) {
				r = sArgs[i].slice(sArgs[i].indexOf('=')+1);
				break;
			}
		}
		return (r.length > 0 ? unescape(r).split(',') : '');
	} else {
		return ['?', '?'];
	}
}

// text node in which ill print latitude and longitude from map's current position
var latLongTextNode = document.createTextNode(' ? ?');
// TODO unificar aspecto, separador
document.getElementsByClassName('leaf-links')[0].appendChild(latLongTextNode);

// Get latitude and longitude from the 'Link' and print it beside it
function printCoords() {
	var link = document.getElementById('link');
	if (link) {
		var aLatLong = argItems(link.href,'ll');
		latLongTextNode.data = ' ' + aLatLong[0] + ' ' + aLatLong[1];
	}
	setTimeout(printCoords, 1000);
}

// Will print current coords each second
setTimeout(printCoords, 1000);
